package com.vision.pdp.Activity;


import com.vision.frame.Bean.ResultObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.core.env.Environment;
import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;

@Controller
@Api(tags = "PTR")
@RequestMapping("/PTR")
public class PTRControl {

    @Resource
    private Environment env;


    @ResponseBody
    @PostMapping(value = "/getPTRTree")
    @ApiOperation(value = "获取PTR树结构（prjCode必填）")
    public ResultObject getFilePath(HttpServletRequest request, HttpServletResponse response, @RequestBody MXGraphDTO mxGraphDTO) {
        ResultObject resultObject = new ResultObject();
        try {
            String prjCode = mxGraphDTO.getPrjCode();
            HashMap<String, Object> prj = new HashMap<>();
            prj.put("Sort", -99);
            prj.put("expand", true);
            prj.put("fCode", prjCode);
            prj.put("fKey", prjCode);
            prj.put("fName", prjCode);
            prj.put("fParent", "");
            prj.put("fParentKey", "");
            prj.put("fSelectTag", "Y");
            prj.put("name", prjCode);
            prj.put("selected", true);
            prj.put("title", prjCode);

            ArrayList<HashMap<String, Object>> arrayList = new ArrayList<>();
            for(int i = 0; i < 10; i++)
            {
                int number = i+1;
                HashMap<String, Object> map = new HashMap<>();
                map.put("Sort", number);
                map.put("expand", false);
                map.put("fCode", "PTR" + number);
                map.put("fKey", "PTR" + number);
                map.put("fName", "PTR" + number);
                map.put("fParent", prjCode);
                map.put("fParentKey", prjCode);
                map.put("fSelectTag", "Y");
                map.put("name", "PTR" + number);
                map.put("selected", false);
                map.put("selected", false);
                map.put("title", "PTR" + number);
                arrayList.add(map);
            }

            prj.put("children", arrayList);

            ArrayList arrayList1 = new ArrayList();
            arrayList1.add(prj);
            resultObject.setRows(arrayList1);


        } catch (Exception e) {
            resultObject.onSetErrorMsg(e);
        }
        return resultObject;
    }




}
